<!DOCTYPE html>
<!-- saved from url=(0050)http://www.jq22.com/demo/jqueryMoblic201812270014/ -->
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <meta name="viewport"
          content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=0">
    <title>购物车</title>
    <link rel="stylesheet" type="text/css" href="/js/shoppingCart/shoppingcart.css">
    <script src="/js/common.js"></script>
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/plugins/jquery-form/jquery.form.js"></script>
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.css" type="text/css"/>
    <script type="text/javascript" src="/js/bootstrap/js/bootstrap.js"></script>
    <script type="text/javascript" src="/js/plugins/messager/jquery.bootstrap.min.js"></script>
    <script type="text/javascript" src="/js/common.js"></script>
    <script>
        $(function () {
            //时间


            var userId = getParams().userId;
            $.get('/users/' + userId + '/shoppingCart', function (data) {
                $('.product').html(data);

                //全选
                $(".product-al").click(function () {
                    var fxk = $(".product-em");
                    var qx = $(".product-all em");
                    qx.toggleClass("product-all-on");
                    if ($(this).find(".product-all em").is(".product-all-on")) {
                        fxk.addClass("product-xz");
                    } else {
                        fxk.removeClass("product-xz");
                    }
                    TotalPrice();
                    shuliang()
                });

                //结算
                $('.product-sett').click(function () {
                    var arr = $.map($(".product-xz"), function (item, index) {
                        return $(item).data('productid');
                    });
                    var countArr = $.map($(".product-em"),function(item, index){
                        if($(item).is(".product-xz")){
                            return parseInt($(item).parents(".product-ckb").siblings().find(".product-num").val());//得到产品数量
                        }
                    });
                    var allPrice = $('.all-price').html();
                    allPrice = allPrice.split('.')[0];
                   $.get('/users/' + userId + '/credits', function (data) {
                        if (data.credit < allPrice) {
                            alert("温馨提示:积分不足");
                        }
                        else {
                            var dateNow = new Date();
                            createDate = dateTransfer(dateNow,'yyyy-MM-dd HH:mm:ss');
                            console.log(createDate);
                            var order = new Date().toLocaleDateString() + '-' + Math.random() * 100000 + userId;
                            $.each(arr, function (index,item) {
                                order = order.split('.')[0];
                                $.get('/users/deleteProducts', {userId:userId, productId:item})
                                $.get('/users/addOrder', {userId:userId,productId:item,count:countArr[index],orderNum:order, createTime:createDate});
                                $.get('/products/' + item + '/changeCount',{count:countArr[index]});
                            })
                            $.get('/users/spendCredits', {id:userId, credit:allPrice}, function (data) {
                                alert("温馨提示:兑换成功")
                                window.location.reload();
                            });
                        }
                    })
                })

            })
            //删除产品
            $(".product").on('click', '.product-del', function () {
                var productId = $(this).data('productid');
                if (confirm("您确定要删除当前商品？")) {
                    $.get('/users/deleteProducts', {userId:userId, productId:productId})
                    $(this).closest(".product-box").remove();
                }

                koncat();
                TotalPrice();
                shuliang();
            });
            //跳转积分商城
            $('#toCreditShop').click(function () {
                $(this).attr('href', '/creditShop.html?userId=' + userId);
            })
        })
    </script>

</head>
<body style="">
<div class="body">
    <div class="shop"><i></i><span>我的购物车</span></div>
    <div class="product">
        <div class="product-box">
            <div class="product-ckb"><em class="product-em"></em></div>
            <div class="product-sx">
                <a href="#">
                    <img src="" class="product-img">
                    <span class="product-name"></span>
                </a>
                <span class="product-price"> <span class="price"></span></span>
                <div class="product-amount">
                    <div class="product_gw">
                        <em class="product-jian">-</em>
                        <input type="text" value="1" class="product-num">
                        <em class="product-add">+</em>
                    </div>
                </div>
                <div class="product-del"><img src="/js/shoppingCart/deleteico.png"></div>
            </div>
        </div>
    </div>
</div>
<div class="product-js">
    <div class="product-al">
        <div class="product-all">
            <em class=""></em>
        </div>
        <div class="all-xz"><span class="product-all-qx">已选</span>
            <div class="all-sl" style="display: inline-block;"><span class="product-all-sl">1</span></div>
        </div>
    </div>
    <a class="product-sett">结算</a>
    <div class="all-product"><span class="all-product-a"><span class="all-price"></span></span></div>
</div>
</div>

<div class="kon-cat" style="display: none;">
    <div class="catkon">
        <div class="kon-box">
            <div class="kon-hz">
                <img src="/js/shoppingCart/cart-air.png">
                <span class="kon-wz">购物车什么都没有</span>
                <a href="" class="kon-lj" id="toCreditShop">去逛逛</a>
            </div>
        </div>
    </div>
</div>

<script src="/js/shoppingCart/jquery-1.10.2.js"></script>
<script src="js/shoppingCart/jquery.min.js"></script>
<script src="/js/shoppingCart/shoppingcart.js" type="text/javascript" charset="utf-8"></script>

</body>
</html>